<?php

namespace Biz;

use Base\BaseOrmModel;
use Base\Exception\NoRecordException;

class Winning extends \Base\BaseBiz
{
    public function getWinningList($where, $now, $size)
    {
        // 获取客户列表
        $winning_list = \Biz\Winning\Winning::getList($where, $now, $size);
        $user = new \Orm\User\UserClass();
        $winning_list_cls = array();
        $winning_list_cls['total'] = $winning_list['total'];
        if($winning_list['lists']) {
            foreach ($winning_list['lists'] as $key => $value) {
                try{
                    $user->loadById($value['user_id']);
                }catch (\Exception $e){
                    $user['nickname'] = '';
                }
                $winning_list_cls['list'][$key]['id'] = $value['id'];
                $winning_list_cls['list'][$key]['username'] = $user['nickname'];
                $winning_list_cls['list'][$key]['coupon_code'] = $value['coupon_code'];
                $winning_list_cls['list'][$key]['coupon_type_name'] = $value['coupon_type_name'];
                $winning_list_cls['list'][$key]['insert_time'] = $value['insert_time'];
                $winning_list_cls['list'][$key]['mome'] = $value['mome'];
            }
        }

        return $winning_list_cls;
    }


    public function getById($id)
    {
        return \Biz\Winning\Winning::getInfo($id);
    }
}